package com.briup.jz.web.controller;

import com.briup.jz.bean.BasePrivilege;
import com.briup.jz.bean.Category;
import com.briup.jz.service.IBasePrivilegeService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

@Api(description="用户权限相关接口")
@Validated
@RestController
@RequestMapping("/basePrivilege")
public class BasePrivilegeController {
    @Autowired
    private IBasePrivilegeService basePrivilegeService;

    @ApiOperation(value = "查询所有权限信息")
    @GetMapping("query")
    public Message query(){
        List<BasePrivilege> list = basePrivilegeService.query();
        return MessageUtil.success(list);
    }



    @ApiOperation(value = "通过id删除权限信息")
    @GetMapping("deleteById")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
    public Message deleteById(@NotNull Long id){
        basePrivilegeService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "保存或更新资讯分类信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "主键",paramType = "form"),
            @ApiImplicitParam(name="name",value = "权限名称",paramType = "form",required = true),
            @ApiImplicitParam(name="description",value = "权限描述",paramType = "form"),
            @ApiImplicitParam(name="route",value = "路径",paramType = "form"),
            @ApiImplicitParam(name="routeName",value = "路径名",paramType = "form"),
            @ApiImplicitParam(name="type",value = "权限类型",paramType = "form"),
            @ApiImplicitParam(name="icon",value = "图标",paramType = "form"),
            @ApiImplicitParam(name="hidden",value = "是否隐藏[1或0]，1为隐藏",paramType = "form"),
            @ApiImplicitParam(name="num",value = "不知道是什么东西的数值",paramType = "form"),
            @ApiImplicitParam(name="parentId",value = "父权限的id",paramType = "form"),
    })
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(BasePrivilege basePrivilege){
        basePrivilegeService.saveOrUpdate(basePrivilege);
        return MessageUtil.success("更新成功");
    }

}
